﻿import QtQuick 2.0
import QtQuick.Controls 1.4

Item {
    property var currentDate: new Date

    property var targetDate: {
        var d = new Date
        d.setDate(17)
        return d
    }

    property var dTime: 50000

    Component.onCompleted: {
        console.log(currentDate, targetDate, targetDate.getDate()-currentDate.getDate(), targetDate.getHours()-currentDate.getHours())
        var dd = targetDate.getDate()-currentDate.getDate()

        if(dd==0){
            dTime = 50000
        }
        else if(dd==1){
            dTime = 500000
        }
        else if(dd==2){
            dTime = 5000000
        }

        //
//        dTime = 10000

//        anim.restart()
    }

    Connections{
        target: mainwindowtest
        onKeyPress: {
            console.log("onPressed===", key)

//            if(key == "w" || key == "W")
//            {
//                imgGirl.y -= 20
//            }
//            if(key == "s" || key == "S")
//            {
//                imgGirl.y += 20
//            }
//            if(key == "a" || key == "A")
//            {
//                imgGirl.x -= 20
//            }
//            if(key == "d" || key == "D")
//            {
//                imgGirl.x += 20
//            }
        }
    }

    Image {
        id: imgBg
        source: "qrc:/bg.png"
    }

    Image {
        id: imgMoon
        x: (1920-width)/2
        y: 30
        source: "qrc:/moon.png"
    }

    Image {
        id: imgCloud2
        x: 1920//1326
        y: 309
        source: "qrc:/yun2.png"
    }

    Image {
        id: imgFloor
        x: (1920-width)/2
        y: 726
        source: "qrc:/floor.png"
    }

    Image {
        id: imgGirl
        x: 1265
        y: 444
        source: "qrc:/girl.png"
    }

    Image {
        id: imgBoy
        x: 311
        y: 322
        source: "qrc:/boy.png"
    }

    Image {
        id: imgCloud1
        x: -420//129
        y: 776
        source: "qrc:/yun1.png"
    }

//    MouseArea{
//        anchors.fill: imgBg
//        onPressed: {

//            console.log("------------------", mouse.x, mouse.y)
//        }
//    }



    ParallelAnimation{
        id: anim
//        running: true
//        loops: Animation.Infinite
        ParallelAnimation{
            PropertyAnimation{target: imgBoy; property: "x"; to: 632; duration: dTime; }
            PropertyAnimation{target: imgBoy; property: "y"; to: 280; duration: dTime; }

            PropertyAnimation{target: imgGirl; property: "x"; to: 906; duration: dTime; }
            PropertyAnimation{target: imgGirl; property: "y"; to: 299; duration: dTime; }
        }
    }

    ParallelAnimation{
        id: animCloud
//        running: true
        loops: Animation.Infinite

        ParallelAnimation{
            PropertyAnimation{target: imgCloud1; property: "x"; from: -420; to: 1920; duration: 50000; }
            PropertyAnimation{target: imgCloud2; property: "x"; from: 1920; to: -420; duration: 50000; }
        }
    }
}
